# PUTS

x = 5
y = 10
z = x + y
puts z

# Same as

x = 5; y = 10; z = x + y
puts z

first_name = "Michael"
last_name = "Choi"

puts "Your name is "
puts first_name
puts last_name

# Same as

puts "Your name is", first_name, last_name

puts "Your name is " + first_name + " " + last_name

puts "First name is #{first_name} and last name is #{last_name}"
# Same as
puts "First name is %s and last name is %s" % [first_name, last_name]

z = 50
puts "Value of z is #{z}"
# Same as
puts "Value of z is %d" % [z]
#Same as
puts "Value of z is %d" % z

=begin
%s for string
%d for decimal
%f for float
=end

puts "I am 5'10\" tall"

# \ = escape
# \t = tab
# \n = new line

# Variables/Classes

class CodingDojo 
  @@no_of_branches = 0 # @@ means class variable - available for all methods AND instances (i.e. all objects for that class)

  def initialize(id, name, address) # Constructor for class
    @branch_id = id # Instance variables are available for all methods of the object (e.g. lines 67-69)
    @branch_name = name 
    @branch_address = address 
    @@no_of_branches += 1 
    puts "\nCreated branch #{@@no_of_branches}" 
  end 
  
  def hello 
    puts "Hello CodingDojo!" 
  end 

  def displayAll 
    puts "Branch ID: %d" % @branch_id 
    puts "Branch Name: %s" % @branch_name 
    puts "Branch Address: %s" % @branch_address 
  end 
end 

# now using above class to create objects 
branch = CodingDojo.new(253, "SF CodingDojo", "Sunnyvale CA") # Local object
branch.displayAll 
branch2 = CodingDojo.new(155, "Boston CodingDojo", "Boston MA") # Local object
branch2.displayAll

def test(a1="Ruby", a2="Perl") 
  puts "The programming language is #{a1}" 
  puts "The programming language is #{a2}" 
end 
 
test "C", "C++" 
test

# Operators

puts 3 + 5
puts 3 + 2
puts a = 5
puts a = a + 2
puts a - 5
puts a += 2 # a = a + 2

# If/Else and While and Switch Statements

x = 1
if x > 2 # Parentheses are optional
   puts "x is greater than 2"
elsif x <= 2 and x > 0
   puts "x is 1"
else
   puts "I can't guess the number"
end

x = 5
puts "x is not 2" if x != 2
# Same as
puts "x is not 2" unless x == 2 # Unless is unique to Ruby

puts "x is greater than 2" if x > 2

x = 1
puts "x is 1" if x == 1

age =  5
case age
when 0 .. 2
    puts "baby"
when 3 .. 6
    puts "little child"
when 7 .. 12
    puts "child"
when 13 .. 18
    puts "youth"
else
    puts "adult"
end

# Loops

# While loop
i = 0
num = 5
begin
   puts "Inside the loop i = #{i}"
   puts "$i is now 3" if i==3
   puts "$i is not 3" unless i==3
   i +=1
end while i < num

# For loop
for i in 0..5 
  puts "Value of local variable is #{i}"

  puts "i is now 3!!!" if i==3
end










